package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author xiaohai
 * @since 2024-09-11
 */

@RestController
@RequestMapping("/lessons")
@Api(tags = "课表相关接口")
@RequiredArgsConstructor
public class LearningLessonController {

    private final ILearningLessonService lessonService;

    /**
     * 根据id分页查询我的课表
     *
     * @param query
     * @return
     */
    @ApiOperation("根据id分页查询课表")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> queryMyLessons(@Validated PageQuery query) {
        return lessonService.queryMyLessons(query);
    }

    /**
     * 查询当前用户最近学习的课程
     * @return
     */
    @GetMapping("/now")
    @ApiOperation("查询当前用户最近学习的课程")
    public LearningLessonVO queryCurrent() {
        return lessonService.queryCurrent();
    }

    /**
     * 根据课程id查询课程信息
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}")
    @ApiOperation("根据课程id查询课程信息")
    public LearningLessonVO queryByCourseId(@PathVariable Long courseId) {
        return lessonService.queryByCourseId(courseId);
    }

    /**
     * 校验当前课程是否已经报名
     * @param courseId
     * @return
     */
    @GetMapping("/{courseId}/valid}")
    @ApiOperation("校验当前课程是否已经报名")
    public Long isLessonValid(
            @ApiParam(value = "课程id", example = "1")
            @PathVariable("courseId") Long courseId) {
        return lessonService.isLessonValid(courseId);
    }

    /**
     * 创建我的学习计划
     *
     * @param dto
     */
    @PostMapping("/plans")
    @ApiOperation("创建我的学习计划")
    public void createLessonPlan(@RequestBody LearningPlanDTO dto) {
        lessonService.createLessonPlan(dto);
    }

    /**
     * 查询我的学习计划
     *
     * @param pageQuery
     * @return
     */
    @GetMapping("/plans")
    @ApiOperation("查询我的学习计划")
    public LearningPlanPageVO queryMyPlan(PageQuery pageQuery) {
        return lessonService.queryMyPlan(pageQuery);
    }
}
